package com.hongkuncheng.cms.handler;


import com.hongkuncheng.cms.exception.BaseException;
import com.hongkuncheng.cms.helper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.servlet.http.HttpServletResponse;

@RestControllerAdvice
public class GlobalExceptionHandler {

    HttpServletResponse response;
    @Autowired
    public void setResponse(HttpServletResponse response) {
        this.response = response;
    }

    /**
     * 捕获FailException
     * @param exception
     * @return
     */
    @ExceptionHandler(BaseException.class)
    public void catchBaseException(BaseException exception) {
        PageHelper.alertAndGoBack(exception.getMessage());
    }

}
